package com.yang.doctorrecruitment.action;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.yang.doctorrecruitment.dao.ApplyDAO;
import com.yang.doctorrecruitment.dao.JobDAO;
import com.yang.doctorrecruitment.dto.Apply;
import com.yang.doctorrecruitment.dto.ReleaseJob;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class GetApplyByUserIDAction extends ActionSupport {
    private JSONArray apply;
    private JSONArray job;
    private JSON jobname;
    public String GetApplyByUserID(){
        Map session= ActionContext.getContext().getSession();
        String UserID= (String) session.get("UserID");
//        通过UserID查询申请列表
        List<Apply> Apply= ApplyDAO.ApplyByUserID(UserID);
        List<ReleaseJob> release=ApplyDAO.ApplyJobByUserID(UserID);
        JSONArray Apparray= JSONArray.parseArray(JSON.toJSONString(Apply));
        JSONArray Jobarray= JSONArray.parseArray(JSON.toJSONString(release));
        job=Jobarray;
        apply=Apparray;
        //查询出来的是两个数组，但是如何把两个数组相关的数据拼接到一起呢？
        //在这里处理，
        if(job!=null&&apply!=null){
            return SUCCESS;
        }else{
            return ERROR;
        }

    }

    public String GetApply(){
        Map session= ActionContext.getContext().getSession();
        String UserID= (String) session.get("UserID");
        List<Apply> Apply= ApplyDAO.ComByJobID(UserID);
        JSONObject object=new JSONObject();
        JSONArray js=new JSONArray();
         for(int i=0;i<Apply.size();i++){
             ReleaseJob Job= JobDAO.getReleseJobByJobID(Apply.get(i).getJobID());

             js.add(Job);

         }
        JSONArray Apparray= JSONArray.parseArray(JSON.toJSONString(Apply));
        job=js;
        apply=Apparray;
        return SUCCESS;
    }
    public JSONArray getApply() {
        return apply;
    }

    public void setApply(JSONArray apply) {
        this.apply = apply;
    }

    public JSONArray getJob() {
        return job;
    }

    public void setJob(JSONArray job) {
        this.job = job;
    }

    public JSON getJobname() {
        return jobname;
    }

    public void setJobname(JSON jobname) {
        this.jobname = jobname;
    }
}
